﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Web.Generics;
using Microsoft.Practices.Unity;
using System.Reflection;
using BolaoDNA.Repositories;
using BolaoDNA.Repositories.NHibernate;

namespace BolaoDNA.WebMvc.Infrastructure
{
    public class UnityMappingFactory : IUnityMappingFactory
    {
        public void GetMappings(IUnityContainer container)
        {
            var implementationAssembly = typeof(BolaoRepository).Assembly;
            var interfaceAssembly = typeof(IBolaoRepository).Assembly;

            foreach (Type implementationType in implementationAssembly.GetTypes())
            {
                foreach (var interfaceType in interfaceAssembly.GetTypes())
                {
                    if ("I" + implementationType.Name == interfaceType.Name)
                    {
                        container.RegisterType(interfaceType, implementationType);
                    }
                }
            }

            container.RegisterType(typeof(Web.Generics.ILogger), typeof(BolaoDNA.WebMvc.Infrastructure.Log4NetLogger));
        }
    }
}
